layui.config({
  base: "js/"
}).use(['form', 'layer', 'jquery', 'layedit', 'laydate'], function () {
  var form = layui.form(),
    layer = parent.layer === undefined ? layui.layer : parent.layer,
    laypage = layui.laypage,
    layedit = layui.layedit,
    laydate = layui.laydate,
    $ = layui.jquery;

  var course = JSON.parse(sessionStorage.getItem("course"));
  var teachers = new Array();

  console.log("course", course, typeof course);

  $('#Cos_id').val(course.Cos_id);
  $('#Cos_name').val(course.Cos_name);

  $('#Cos_stime').val(course.Cos_stime);
  $('#Cos_etime').val(course.Cos_etime);

  // $('#Cos_teacher').each(function () {
  //   $(this).val() ===
  // });

  //创建一个编辑器
  var editIndex = layedit.build('Cos_intro');
  form.on("submit(editCourse)", function (data) {
    data.field.Cos_intro = layedit.getContent(editIndex);
    //弹出loading
    var index = layer.msg('数据提交中，请稍候', {icon: 16, time: 3000, shade: 0.8});
    $.ajax({
      url: "/api/course/" + data.field.Cos_id,
      type: "PUT",
      data: data.field,
      dataType: "json",
      success: function (data) {
        console.log(data);
        layer.close(index);
        top.layer.msg("修改成功！");
        layer.closeAll("iframe");
      },
      error: function (data) {
        layer.close(index);
        top.layer.msg("修改失败！");
      }
    });
    return false;
  })

});
